<?php
/**
 * 案例添加管理页面
 * author:wang
 * mail:970633164@qq.com
 */
define("PHP_IN", true);
require "../include/init.php";
require "checklogin.php";
require ROOT_PATH."cms/smart_connection.php";

$sql = "SELECT * FROM case_type";   //案例分类选择
$result = $db->query($sql);
$case_type = $db->fetch_all($result);

if (isset($_POST['dosubmit'])) {
    $title = $_POST['title'];
    $intro = $_POST['intro'];
    $content = isset($_POST['editorValue']) ? $_POST['editorValue'] : "";
    $url = $_POST['url'];
    $isdisplay = $_POST['isdisplay'];
    $case_type = $_POST['case_type'];
    $t = time();
    $thumbname = "";
    if ($_FILES['photo']['error'] == 0) {
        $filename = file_ext($_FILES['photo']['name']);
        $thumbname = $t.rand(10000,99999).$filename;
        $path = $cases_thumb_up.$thumbname;
        $upload = move_uploaded_file($_FILES['photo']['tmp_name'],$path);
    }

    $sql ="INSERT INTO cases (title,intro,content,url,cid,thumb,isdisplay,addtime) VALUES
      ('$title','$intro','$content','$url','$case_type','$thumbname','$isdisplay','$t')";
    $result = $db->query($sql);
    if($result){
       alert("添加成功","case_list.php");
    }else{
        alert("添加失败");
    }

}

$smarty->display("case_add.tpl");
$db->close();
?>